﻿@model DataEntity.OffRequisitionBillDetail
<div class="div_center">

    @using (Html.BeginForm("", "", FormMethod.Post, new { id = "requisitionbilldetailfm", name = "requisitionbilldetailfm" }))
    { 
        <fieldset class="datebox-button" style="height: auto; text-align: left; padding-top: 8px; padding-right: 8px; padding-bottom: 8px; padding-left: 8px;">
            <legend class="panel-title">物品明细信息</legend>


           <table class="TableBlock">
           
            <tr>
             
                <td  class="TableLabel" >
                    @Html.HiddenFor(model=>model.ID)
                    @Html.HiddenFor(model=>model.OffRequisitionBillID)
                    物品类别:
                </td>
                <td class="TableData" >
                    @Html.TextBoxFor(model => model.OffGoods.OffGoodsClassID, new {id="OffGoodsClassID",name="OffGoodsClassID" })  
                </td>
                <td  class="TableLabel" >
                   
                    物品名称:
                </td>
                <td class="TableData" >
                    @Html.TextBoxFor(model => model.OffGoodsID)  
                </td>
               
            </tr>
             <tr>
                <td class="TableLabel" >
                  单价:
                </td>
                <td class="TableData" >
                         @Html.TextBoxFor(model => model.Price)
                </td>
                <td  class="TableLabel">
                税后价格:
                </td>
                <td class="TableData">
                      @Html.TextBoxFor(model => model.AfterTaxPrice)
                     
                </td>
            </tr>
            <tr>
                
                <td  class="TableLabel">
                  计量单位:
                </td>
                <td class="TableData">
                       @Html.TextBoxFor(model => model.OffGoods.Unit, new {id="Unit",name="Unit",style="width:80px" })
                     
                </td>
                <td class="TableLabel" >
                   出货数量:
                </td>
                <td class="TableData" >
                         @Html.TextBoxFor(model => model.Quantity, new { style="width:100px"})   库存数: <span style="color:red;font-size:14px" id="Inventory" name="Inventory">@(Model.OffGoods!=null?Model.OffGoods.Inventory:0)</span>
                </td>
            </tr>
               
            <tr>
                <td  class="TableLabel">
                    备注:
                </td>
                <td class="TableData" colspan="3">
                    
                        @Html.TextAreaFor(model => model.Remark, new { cols = "3", rows = "4", style = "height:70px;width: 93%; text-align: left;" })
                       
                </td>
            </tr>
        </table>

        </fieldset>
    }

</div>


<script>
    $(function () {
        var _form = $("#requisitionbilldetailfm");
        var _key = $("#ID", $("#requisitionbilldetailfm")).val();
      
        //if (_key == "0") {
        //    $("#Name", _form).validatebox({ required: true });
            
        //}
        //else {
        //    $("#Name", _form).attr("readonly", "readonly");
        //    $("#Name", _form).addClass("BigStatic");

        //}
        Arraymap = function (array, callback, thisArg) {
           
            var temps = [];
            for (var i = 0; i < array.length; i++) {
                var item = callback.call(thisArg, array[i], i, array);
                
                temps.push(item);
            }

            return temps;
        };
      ArrayContains=function(arr, str) {
            var i = arr.length;
            while (i--) {
                
                if (arr[i] == str) {
                    return true;
                }
            }
            return false;
        }
        $("#Quantity", _form).validatebox({ required: true, validType: ['integer'] });
        
        $("#Unit", _form).attr("readonly", "readonly");
        $("#Unit", _form).addClass("BigStatic");
        $("#Price", _form).attr("readonly", "readonly");
        $("#Price", _form).addClass("BigStatic");
        $("#AfterTaxPrice", _form).attr("readonly", "readonly");
        $("#AfterTaxPrice", _form).addClass("BigStatic");
        var _getGoodsData = function (goodsclassid) {
            var url = "/Goods/GoodsJsonForCombobox";
            
            $.post(url,{goodsclassid:goodsclassid},function (data) {
                $("#OffGoodsID", _form).combobox("loadData", data);
            });
        };
        var _getGoodUnit = function (goodsid) {
            var url = "/Goods/GetGoodsUnit";

            $.post(url, { goodsid: goodsid }, function (data) {
                $("#Unit", _form).val(data);
            });
        };
        var _getGoodInventory = function (goodsid) {
            var url = "/Goods/GetGoodsInventory";

            $.post(url, { goodsid: goodsid }, function (data) {
                $("#Inventory", _form).text(data);
            });
        };
        var _getGoodsPrice = function (goodsid) {
            var url = "/Goods/GetGoodsPrice";

            $.post(url, { goodsid: goodsid }, function (data) {
                $("#Price", _form).val(data);
            });
        };
        var _getGoodTaxPrice = function (goodsid) {
            var url = "/Goods/GetGoodsTaxPrice";

            $.post(url, { goodsid: goodsid }, function (data) {
                
                $("#AfterTaxPrice", _form).val(data);
            });
        };
        $("#OffGoodsID", _form).combobox({
            required: true,
            onChange: function (newValue, oldValue) {
                if (!(newValue == undefined || newValue == null || newValue == "")) {
                    _getGoodUnit(newValue);
                    _getGoodInventory(newValue);
                    _getGoodTaxPrice(newValue);
                    _getGoodsPrice(newValue);
                }
            },
            onLoadSuccess: function () {
                var data = $(this).combobox("getData");
              
                if (data.length > 0) {
                    var value = $(this).combobox("getValue");
                  
                    var valueArray = Arraymap(data, function (val) { return val.value });
                    if (!ArrayContains(valueArray, value)) {
                        
                        $(this).combobox("setValue", data[0].value);
                    }
                }
                else {
                   
                    $(this).combobox("setValue", "");
                }
            }
        });

        $("#OffGoodsClassID", _form).combobox({
            url: "/Goods/GoodsClassJsonForCombobox",
            required: true,
            onChange: function (newValue, oldValue) {
                if (!(newValue==undefined||newValue==null||newValue=="")) {
                    _getGoodsData(newValue);
                }
            },
            onLoadSuccess: function () {

                var data = $(this).combobox("getData");
                
                if (data.length > 0) {
                    var value = $(this).combobox("getValue");
                   
                    var valueArray = Arraymap(data, function (val) { return val.value });
                   
                    if (!ArrayContains(valueArray,value)) {
                       
                        $(this).combobox("setValue", data[0].value);
                    }
                    else {
                        var value = $(this).combobox("getValue");
                       
                        var callback = $(this).combobox("options").onChange;
                        callback.call(this, value);
                    }
                }
                else {
                    $(this).combobox("setValue", "");
                }
            }
        });
    });
  

</script>
